//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<CLocalFile.cpp>
///	@path	~/src/database/xres/
///	@date	2007/11/26
///	@desc	Local file class.

#include "config/config.h"

#include "database/xres/CLocalFile.h"

namespace xeres {

	IMPL_IOBJECT_CLASS( CLocalFile );

	// CLocalFile
	CLocalFile::CLocalFile( void )
	{
	}

	// ~CLocalFile
	CLocalFile::~CLocalFile( void )
	{
	}

	// GetInfo
	bool CLocalFile::GetInfo( DataInfo& datainfo )
	{
		datainfo.m_type = DATA_FILE;
		datainfo.m_size = op().Size();
		op().GetFileTime( datainfo.m_created , datainfo.m_accessed , datainfo.m_modified );
		return true;
	}

	// GetPath
	WString CLocalFile::GetPath( void )
	{
		return op().GetFilePath();
	}

	// Read
	size_t CLocalFile::Read( void * data , size_t size )
	{
		size_t readbytes = 0;
		FILE_STATUS status;
		if( ( status = op().Read( data , size , &readbytes ) ) == FILE_READY )
			return readbytes;
		//return ((size_t)-0);
		throw ( status );
	}

	// Write
	size_t CLocalFile::Write( const void * data , size_t size )
	{
		size_t writebytes = 0;
		FILE_STATUS status;
		if( ( status = op().Write( data , size , &writebytes ) ) == FILE_READY )
			return writebytes;
		//return ((size_t)-0);
		throw ( status );
	}
	// Seek
	bool CLocalFile::Seek( int64 pos , bool abs_seek )
	{
		return op().Seek( pos , abs_seek );
	}
	// SeekEof
	bool CLocalFile::SeekEof( void )
	{
		return op().SeekEof();
	}
	// Tell
	uint64 CLocalFile::Tell( void )
	{
		return op().Tell();
	}

} // namespace xeres
